package com.test.study.ToolsUtils.excelUtil;

import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.junit.Test;

/**
 * 
 * @author huyong
 *
 */

public class ExcelUtils {
	/**
	 * 创建一个Excel文件
	 * huyong
	 * 20192019年2月28日
	 * @throws Exception 
	 */
	public static void  createExcel(String path) throws Exception {
		//1.创建一个工作薄对象
		 @SuppressWarnings("resource")
		HSSFWorkbook workbook=new HSSFWorkbook();
		//2.创建工作表对象
		 HSSFSheet createSheet = workbook.createSheet("工作表对像");
		 //3.这里需要设置单元格的样式
		 HSSFCellStyle createCellStyle = workbook.createCellStyle();
		 createCellStyle.setBorderBottom(BorderStyle.DOUBLE);
		 createCellStyle.setBorderTop(BorderStyle.THICK);
		 createCellStyle.setFillBackgroundColor((short)100);
		 
		 //创建当前动作表的行
		 HSSFRow createRow = createSheet.createRow(10);//这儿是一次性创建10行
		 //定位指定的单元格
		 createRow.createCell(0).setCellStyle(createCellStyle);
		 createRow.createCell(0).setCellValue("huyong");
		 //保存excel文件
		 FileOutputStream outputStream=new FileOutputStream(path);
		 workbook.write(outputStream);
		
	}
	@Test
	public void test() throws Exception {
		String path="/Users/huyong/App/file/test.xlsx";
		createExcel(path);
	}

}
